package com.hzz.code;

/**
 * @author ：hzz
 * @description：TODO
 * @date ：2021/6/28 10:42
 */

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.io.Serializable;

public class ResponseResult<T> implements Serializable {
    private String errorCode;
    private String message;
    private String responseId;
    private T data;

    private ResponseResult() {
        this.errorCode = CommonResultCode.SUCCESS.getCode();
        this.message = "执行成功!";
        this.responseId = null;
        this.data = null;
    }

    public static ResponseResult<Object> getOK() {
        return getOK((Object)null);
    }

    public static <T> ResponseResult<T> getOK(T obj) {
        return getOK("执行成功!", obj);
    }

    public static <T> ResponseResult<T> getOK(String message, T obj) {
        ResponseResult<T> result = new ResponseResult();
        result.setMessage(message);
        result.setData(obj);
        return result;
    }

    public static ResponseResult<Object> getError(ResultCode resultCode) {
        return getError(resultCode, resultCode.getMsg(), (Object)null);
    }

    public static ResponseResult<Object> getError(ResultCode commonResultCode, String msg) {
        return getError(commonResultCode, msg, (Object)null);
    }

    public static ResponseResult<Object> getError(String errorCode, String msg) {
        ResponseResult<Object> result = new ResponseResult();
        result.setErrorCode(errorCode);
        result.setMessage(msg);
        result.setData((Object)null);
        return result;
    }

    public static <T> ResponseResult<T> getError(ResultCode resultCode, String message, T obj) {
        ResponseResult<T> result = new ResponseResult();
        result.setErrorCode(resultCode.getCode());
        result.setMessage(message);
        result.setData(obj);
        return result;
    }

    @JSONField(
            serialize = false,
            deserialize = false
    )
    @JsonIgnore
    public boolean isSuccess() {
        return this.errorCode.equals(CommonResultCode.SUCCESS.getCode());
    }

    public String toString() {
        return "ResponseResult{errorCode='" + this.errorCode + '\'' + ", message='" + this.message + '\'' + ", responseId='" + this.responseId + '\'' + ", data=" + this.data + '}';
    }

    public String getErrorCode() {
        return this.errorCode;
    }

    public String getMessage() {
        return this.message;
    }

    public String getResponseId() {
        return this.responseId;
    }

    public T getData() {
        return this.data;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void setResponseId(String responseId) {
        this.responseId = responseId;
    }

    public void setData(T data) {
        this.data = data;
    }

    public boolean equals(Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof ResponseResult)) {
            return false;
        } else {
            ResponseResult<?> other = (ResponseResult)o;
            if (!other.canEqual(this)) {
                return false;
            } else {
                label59: {
                    Object this$errorCode = this.getErrorCode();
                    Object other$errorCode = other.getErrorCode();
                    if (this$errorCode == null) {
                        if (other$errorCode == null) {
                            break label59;
                        }
                    } else if (this$errorCode.equals(other$errorCode)) {
                        break label59;
                    }

                    return false;
                }

                Object this$message = this.getMessage();
                Object other$message = other.getMessage();
                if (this$message == null) {
                    if (other$message != null) {
                        return false;
                    }
                } else if (!this$message.equals(other$message)) {
                    return false;
                }

                Object this$responseId = this.getResponseId();
                Object other$responseId = other.getResponseId();
                if (this$responseId == null) {
                    if (other$responseId != null) {
                        return false;
                    }
                } else if (!this$responseId.equals(other$responseId)) {
                    return false;
                }

                Object this$data = this.getData();
                Object other$data = other.getData();
                if (this$data == null) {
                    if (other$data != null) {
                        return false;
                    }
                } else if (!this$data.equals(other$data)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(Object other) {
        return other instanceof ResponseResult;
    }

    public int hashCode() {
        int PRIME = 1;
        int result1 = 1;
        Object $errorCode = this.getErrorCode();
        int result = result1 * 59 + ($errorCode == null ? 43 : $errorCode.hashCode());
        Object $message = this.getMessage();
        result = result * 59 + ($message == null ? 43 : $message.hashCode());
        Object $responseId = this.getResponseId();
        result = result * 59 + ($responseId == null ? 43 : $responseId.hashCode());
        Object $data = this.getData();
        result = result * 59 + ($data == null ? 43 : $data.hashCode());
        return result;
    }
}

